<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="服务名称" prop="ServeName">
        <el-input v-model="formData.ServeName" placeholder="请输入服务名称" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="服务介绍" prop="ServeIntroduce">
        <el-input v-model="formData.ServeIntroduce" placeholder="请输入服务介绍" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="服务秒杀" prop="ServeSeckill">
        <el-input v-model="formData.ServeSeckill" placeholder="请输入服务秒杀" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="服务价格" prop="ServePrice">
        <el-input v-model="formData.ServePrice" placeholder="请输入服务价格" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="服务有效期" prop="ServeValidity">
        <el-input v-model="formData.ServeValidity" placeholder="请输入服务有效期" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-form-item label="服务图片" prop="ServeImg" required>
        <el-upload ref="ServeImg" :file-list="ServeImgfileList" :action="ServeImgAction" multiple
          :before-upload="ServeImgBeforeUpload" list-type="picture-card">
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  components: {},
  props: [],
  data () {
    return {
      formData: {
        ServeName: undefined,
        ServeIntroduce: undefined,
        ServeSeckill: undefined,
        ServePrice: undefined,
        ServeValidity: undefined,
        ServeImg: null
      },
      rules: {
        ServeName: [{
          required: true,
          message: '请输入服务名称',
          trigger: 'blur'
        }],
        ServeIntroduce: [{
          required: true,
          message: '请输入服务介绍',
          trigger: 'blur'
        }],
        ServeSeckill: [{
          required: true,
          message: '请输入服务秒杀',
          trigger: 'blur'
        }],
        ServePrice: [{
          required: true,
          message: '请输入服务价格',
          trigger: 'blur'
        }],
        ServeValidity: [{
          required: true,
          message: '请输入服务有效期',
          trigger: 'blur'
        }]
      },
      ServeImgAction: 'https://jsonplaceholder.typicode.com/posts/',
      ServeImgfileList: []
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    submitForm () {
      this.$refs['elForm'].validate(valid => {
        // if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm () {
      this.$refs['elForm'].resetFields()
    },
    ServeImgBeforeUpload (file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    }
  }
}

</script>
<style>
.el-upload__tip {
  line-height: 1.2;
}

</style>
